﻿using System;

namespace Yamfinder.Data
{
    public static class LexicalFilterHelper
    {
        public static LexicalFilter AddFilterData(this LexicalFilter lexicalFilter, string key, object data)
        {
            lexicalFilter.FilterData.Add(key, data);
            return lexicalFilter;
        }
        
        public static string GetStringData(this LexicalFilter lexicalFilter, string key)
        {
            if (!lexicalFilter.FilterData.ContainsKey(key))
                throw new ArgumentException("Data does not contain the specified key!", "key");

            var result = lexicalFilter.FilterData[key].ToString();

            if (result == null)
                throw new ArgumentException("Data was not of the correct type", "lexicalFilter");

            return result;
        }

        public static double GetDoubleData(this LexicalFilter lexicalFilter, string key)
        {
            if (!lexicalFilter.FilterData.ContainsKey(key))
                throw new ArgumentException("Data does not contain the specified key!", "key");

            var result = (double)lexicalFilter.FilterData[key];

            return result;
        }

        public static long GetLongData(this LexicalFilter lexicalFilter, string key)
        {
            if (!lexicalFilter.FilterData.ContainsKey(key))
                throw new ArgumentException("Data does not contain the specified key!", "key");

            var result = (long)lexicalFilter.FilterData[key];

            return result;
        }

        public static DateTime GetDateTimeData(this LexicalFilter lexicalFilter, string key)
        {
            if (!lexicalFilter.FilterData.ContainsKey(key))
                throw new ArgumentException("Data does not contain the specified key!", "key");

            var result = (DateTime)lexicalFilter.FilterData[key];

            return result;
        }
    }
}